package com.example.wechattakeaway.controller;

import com.example.wechattakeaway.accessctro.RolePermission;
import com.example.wechattakeaway.form.merchantform.InsertMerchantForm;
import com.example.wechattakeaway.form.merchantform.UpdateMerchantForm;
import com.example.wechattakeaway.service.MerchantService;
import com.example.wechattakeaway.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/MerchantController")
@Api(tags = "商家信息管理模块")
public class MerchantController {

    @Autowired
    MerchantService merchantService;


    @ApiOperation(value = "添加商家信息",notes = "商家web端")
    @PostMapping("/insertMerchant")
    public ResultVO insertMerchant(InsertMerchantForm insertMerchantForm){
        return merchantService.insertMerchant(insertMerchantForm);
    }

    @ApiOperation(value = "编辑商家信息",notes = "商家web端")
    @PostMapping("/updateMerchant")
    public ResultVO updateMerchant(UpdateMerchantForm updateMerchantForm){
        return merchantService.updateMerchant(updateMerchantForm);
    }

    @ApiOperation(value = "根据商家id查询商家信息",notes = "商家web端以及小程序端")
    @ApiImplicitParam(name="merchantId",value="商家id",example = "1",dataType = "Integer",paramType = "query")
    @GetMapping("/selectMerchantById")
    public ResultVO selectMerchantById(@RequestParam("merchantId") Integer merchantId){
        System.out.println("++++++++++++"+merchantId.toString());
        return merchantService.selectMerchantById(merchantId);
    }

    @ApiOperation(value = "查询所有商家信息列表",notes = "小程序端")
    @GetMapping("/selectAllMerchant")
    public ResultVO selectAllMerchant(){
        return merchantService.selectAllMerchant();
    }


    @ApiOperation(value = "根据商家类型查询对应商家列表",notes = "小程序端")
    @ApiImplicitParam(name="merchantType",value="商家类型",example = "1",dataType = "String",paramType = "query")
    @GetMapping("/selectMerchantByType")
    public ResultVO selectMerchantByType(@RequestParam("merchantType") String merchantType){

        return merchantService.selectMerchantByType(merchantType);
    }

    @ApiOperation(value = "根据商家id删除商家",notes = "商家web端")
    @PostMapping("/deleteMerchant")
    public ResultVO deleteMerchant(Integer merchantId){

        return merchantService.deleteMerchant(merchantId);
    }

    @ApiOperation(value = "在进入某一分类之后，根据商家订单数量（降序）查询对应商家列表",notes = "小程序端")
    @ApiImplicitParam(name="merchantType",value="商家类型",example = "1",dataType = "String",paramType = "query")
    @GetMapping("/selectByTypeAndOrder")
    public ResultVO selectByTypeAndOrder(@RequestParam("merchantType") String merchantType){
        return merchantService.selectByTypeAndOrder(merchantType);
    }

    @ApiOperation(value = "首页根据商家订单数量（降序）查询对应商家列表",notes = "小程序端")
    @GetMapping("/selectByOrderNum")
    public ResultVO selectByOrderNum(){
        return merchantService.selectByOrderNum();
    }

    @ApiOperation(value = "在进入分类之后，根据商家被关注数量（降序）查询对应商家列表",notes = "小程序端")
    @ApiImplicitParam(name="merchantType",value="商家类型",example = "1",dataType = "String",paramType = "query")
    @GetMapping("/selectByAttenAndType")
    public ResultVO selectByAttenAndType(@RequestParam("merchantType") String merchantType){
        return merchantService.selectByAttenAndType(merchantType);
    }

    @ApiOperation(value = "首页根据商家被关注数量（降序）查询对应商家列表",notes = "小程序端")
    @GetMapping("/selectByAttenNum")
    public ResultVO selectByAttenNum(){
        return merchantService.selectByAttenNum();
    }

    @ApiOperation(value = "根据负责人id查询商家信息" ,notes = "web端")
    @GetMapping("/selectMerByUser")
    public ResultVO selectMerByUser(@RequestParam("userId") Integer userId){
        return merchantService.selectMerByUser(userId);
    }

    @ApiOperation("根据商家id更新图片")
    @PostMapping("/UpdateImgById")
    public ResultVO UpdateImgById(@RequestParam("file") MultipartFile file, Integer merchantId){
        return merchantService.UpdateImgById(file, merchantId);
    }

}
